﻿@inject IStringLocalizer<DateTimeRangeBindValue> Localizer

<div class="row g-3">
    <div class="col-12 col-sm-6">
        <DateTimeRange @bind-Value="@DateTimeRangeValue" OnValueChanged="v => OnValueChanged(v, 1)" />
    </div>
    <div class="col-12 col-sm-6">
        <BootstrapInputGroup>
            <BootstrapInputGroupLabel DisplayText="@Localizer["Limit"]" />
            <Display TValue="string" Value="@_range2" />
        </BootstrapInputGroup>
    </div>
</div>

@code {
    private DateTimeRangeValue DateTimeRangeValue { get; set; } = new();

    private string? _range2;

    private Task OnValueChanged(DateTimeRangeValue val, int index)
    {
        var ret = "";
        if (val.Start != DateTime.MinValue)
        {
            ret = val.Start.ToString("yyyy-MM-dd");
        }
        if (val.End != DateTime.MinValue)
        {
            ret = $"{ret} - {val.End:yyyy-MM-dd}";
        }
        if (index == 1)
        {
            _range2 = ret;
        }
        return Task.CompletedTask;
    }
}
